import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class Email {

private static String SMPT_HOSTNAME = "smtp.gmail.com";
private static String SMPT_PORT = "587";
private static String USERNAME = "javifalcesrobotrader";
private static String PASSWORD = "6uidza3-";

    //String [] ticker={"EUR","GBP","USD","USD","AUD","EUR"};   //Todas las posiblidades FOREX
    //String [] exchange={"USD","USD","CHF","CAD","USD","JPY"};//
    String []divisa={"EUR.USD","GBP.USD","USD.CHF","USD.CAD","AUD.USD"};
    
                            //gestion tiempo
            Calendar calendario = Calendar.getInstance();


public void  compra(int seleccion) {
    Properties props = new Properties();
    props.put("mail.smtp.host", SMPT_HOSTNAME);
    props.put("mail.smtp.port",SMPT_PORT );
    props.put("mail.from","javifalcesrobotrader@gmail.com");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.auth", "true");
    props.put("mail.debug", "true");


            


    Session session = Session.getInstance(props, new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(USERNAME, PASSWORD);
        }
    });
    try {
        MimeMessage msg = new MimeMessage(session);
        msg.setFrom();
        msg.setRecipients(Message.RecipientType.TO,
                          "javifalces@gmail.com");
        
           int hora =calendario.get(Calendar.HOUR_OF_DAY);
           int minutos = calendario.get(Calendar.MINUTE);
           int segundos = calendario.get(Calendar.SECOND);
        msg.setSubject("[Robot] Compra:"+divisa[seleccion]+"( "+hora + ":" + minutos + ":" + segundos+" )");
        
        msg.setSentDate(new Date());
        
        msg.setText("Se ha comprado o vendido");
        Transport.send(msg);
     } catch (MessagingException mex) {
        System.out.println("send failed, exception: " + mex);
     }
    }



public void  vende(int seleccion) {
    Properties props = new Properties();
    props.put("mail.smtp.host", SMPT_HOSTNAME);
    props.put("mail.smtp.port",SMPT_PORT );
    props.put("mail.from","javifalcesrobotrader@gmail.com");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.auth", "true");
    props.put("mail.debug", "true");

    Session session = Session.getInstance(props, new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(USERNAME, PASSWORD);
        }
    });
    try {
        MimeMessage msg = new MimeMessage(session);
        msg.setFrom();
        msg.setRecipients(Message.RecipientType.TO,
                          "javifalces@gmail.com");
        
        
        
           int hora =calendario.get(Calendar.HOUR_OF_DAY);
           int minutos = calendario.get(Calendar.MINUTE);
           int segundos = calendario.get(Calendar.SECOND);
        msg.setSubject("[Robot] Vende:"+divisa[seleccion]+"( "+hora + ":" + minutos + ":" + segundos+" )");
        
        msg.setSentDate(new Date());
        
        msg.setText("Se ha comprado o vendido");
        Transport.send(msg);
     } catch (MessagingException mex) {
        System.out.println("send failed, exception: " + mex);
     }
    }
}